package com.yipei.business.controller;

import com.yipei.business.domain.MlBankCard;
import com.yipei.business.service.IMlBankCardService;
import com.yipei.common.annotation.Log;
import com.yipei.common.core.controller.BaseController;
import com.yipei.common.core.domain.AjaxResult;
import com.yipei.common.core.page.TableDataInfo;
import com.yipei.common.enums.BusinessType;
import com.yipei.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户银行Controller
 *
 * @author yipei
 * @date 2024-12-23
 */
@RestController
@RequestMapping("/business/card")
@Api(tags = "用户银行", description = "用户银行管理")
public class MlBankCardController extends BaseController {
    @Autowired
    private IMlBankCardService mlBankCardService;

    /**
     * 查询用户银行列表
     */
    @ApiOperation("用户银行获取数据")
    //@PreAuthorize("@ss.hasPermi('business:card:list')")
    @GetMapping("/list")
    public TableDataInfo list(MlBankCard mlBankCard) {
        startPage();
        List<MlBankCard> list = mlBankCardService.selectMlBankCardList(mlBankCard);
        return getDataTable(list);
    }

    /**
     * 导出用户银行列表
     */
    @ApiOperation("用户银行导出数据")
    //@PreAuthorize("@ss.hasPermi('business:card:export')")
    @Log(title = "用户银行", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MlBankCard mlBankCard) {
        List<MlBankCard> list = mlBankCardService.selectMlBankCardList(mlBankCard);
        ExcelUtil<MlBankCard> util = new ExcelUtil<MlBankCard>(MlBankCard.class);
        util.exportExcel(response, list, "用户银行数据");
    }

    /**
     * 获取用户银行详细信息
     */
    @ApiOperation("用户银行通过id获取数据")
    //@PreAuthorize("@ss.hasPermi('business:card:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(mlBankCardService.selectMlBankCardById(id));
    }

    /**
     * 新增用户银行
     */
    @ApiOperation("用户银行新增数据")
    //@PreAuthorize("@ss.hasPermi('business:card:add')")
    @Log(title = "用户银行", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MlBankCard mlBankCard) {
        return toAjax(mlBankCardService.insertMlBankCard(mlBankCard));
    }

    /**
     * 修改用户银行
     */
    @ApiOperation("用户银行修改数据")
    //@PreAuthorize("@ss.hasPermi('business:card:edit')")
    @Log(title = "用户银行", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MlBankCard mlBankCard) {
        return toAjax(mlBankCardService.updateMlBankCard(mlBankCard));
    }

    /**
     * 删除用户银行
     */
    @ApiOperation("用户银行删除数据")
    //@PreAuthorize("@ss.hasPermi('business:card:remove')")
    @Log(title = "用户银行", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(mlBankCardService.deleteMlBankCardByIds(ids));
    }


    @ApiOperation("获取当前用户银行卡数据")
    //@PreAuthorize("@ss.hasPermi('business:card:list')")
    @GetMapping("/tdAccBanklist")
    public TableDataInfo tdAccBanklist() {
        List<MlBankCard> list = mlBankCardService.selectTdAccBankList();
        return getDataTable(list);
    }
}
